package com.meshnetics.gb.stack.mac.primitives;

import com.meshnetics.gb.stack.mac.type.MACStatus;
import com.meshnetics.gb.type.impl.zcl.Bitmap;
import com.meshnetics.gb.type.impl.zcl.BitmapEditor;
import com.meshnetics.gb.type.impl.zcl.TypeBitmap;

/**
 * WRITE DESCRIPTION HERE
 *
 * @author AKovylin
 */
class Utils {
    private Utils() {
    }

    public static void checkStatus(MACStatus status, byte[] allowedCodes) {
        for (int i = 0; i < allowedCodes.length; i++) {
            if (allowedCodes[i] == status.getCode()) {
                return;
            }
        }
        throw new IllegalArgumentException("invalid status " + status);
    }

    public static Bitmap createBitmapSecAndAcl(boolean secUse, int aclEntry) {
        if (aclEntry < 0 || aclEntry > 8) {
            throw new IllegalArgumentException("invalid aclEntry, must be in range 0-8");
        }
        BitmapEditor be = new BitmapEditor(TypeBitmap.BITMAP_8);
        be.setBit(0, secUse);
        be.setBits(1, 5, aclEntry);
        return be.create();
    }
}
